//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
  },
  onLoad: function () {
    // 在没有 open-type=getUserInfo 版本的兼容处理
    wx.getUserInfo({
      success: res => {
        // console.log(res);
        app.globalData.userInfo = res.userInfo
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  unbinding(){
    wx.login({
      success: function (res) {
        // console.log('新code', res.code);
        wx.setStorageSync('wxCode', res.code)
        if (res.code) {
          // console.log("解绑tonkon", wx.getStorageSync('token'));
          wx.request({
            url: app.api.unbinding + '?weChatCode=' + wx.getStorageSync('wxCode'),
            header: {
              "Content-Type": "application/x-www-form-urlencoded",
              "Authorization": wx.getStorageSync('token'),
            },
            method: "POST",
            data: {
            },
            success: function (res) {
              if (res.data.code == 0) {
                wx.showToast({
                  title: '账号解绑成功',
                  // icon: 'loading',
                  // duration: 1500
                })
                wx.reLaunch({
                  url: '/pages/login/login'
                })
              } else {
                wx.showToast({
                  title: res.data.message,
                })
              }

            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    });
  }
})
